import QtQuick

ListView{
    id: listView

    enum MoveState{
        Hide,
        Display,
        Runing,
        Complete
    }

    enum MoveDirection{
        NoMove,
        UpToDown,
        DownToUp
    }
    property int moveDirection: PullListViewV1.NoMove

    property int headerState: PullListViewV1.Hide
    property string headerText: ""

    property int footerState: PullListViewV1.Hide
    property string footerText: ""

    property real moveStartContentY: 0
    //开始滑动
    onMovementStarted: {
         console.log("onMovementStarted")
        moveStartContentY = contentY
    }

    onContentYChanged: {
        if(moving)
        {
            moveDirection = (contentY - moveStartContentY < 0) ? PullListViewV1.UpToDown : PullListViewV1.DownToUp

            switch(moveDirection){
            case PullListViewV1.UpToDown:{
                if(atYBeginning && PullListViewV1.Hide === headerState && PullListViewV1.Hide === footerState) {
                    headerState = PullListViewV1.Display
                }
            }break;
            case PullListViewV1.DownToUp:{
                if(atYEnd && PullListViewV1.Hide === footerState && PullListViewV1.Hide === headerState) {
                    footerState = PullListViewV1.Display
                }
            }break;
            default:break;
            }
        }
    }

    //结束滑动
    onMovementEnded: {
        switch(moveDirection){
        case PullListViewV1.UpToDown:{
            if(atYBeginning && PullListViewV1.Display === headerState) {
                headerState = PullListViewV1.Runing
            }else if(headerState !== PullListViewV1.Hide){
                headerState = PullListViewV1.Hide
            }

        }break;
        case PullListViewV1.DownToUp:{
            if(atYEnd && PullListViewV1.Display === footerState) {
                footerState = PullListViewV1.Runing
            }else if(footerState !== PullListViewV1.Hide){
                footerState = PullListViewV1.Hide
            }
        }break;
        default:break;
        }

        moveDirection = PullListViewV1.NoMove
    }
}
